package com.application.meizhi.adapter;

import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.application.meizhi.R;
import com.application.meizhi.base.BaseRecyclerAdapter;
import com.application.meizhi.model.douban.DouBanMeiZhi;
import com.application.meizhi.uitl.glideUtils.GlideImgManager;
import com.bumptech.glide.request.target.SizeReadyCallback;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by gskl on 16/10/10.
 */

public class DouBanListAdapter extends BaseRecyclerAdapter<DouBanMeiZhi> {
    public DouBanListAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_douban_list, parent, false);
        return new DouBanListHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        DouBanListHolder holder = (DouBanListHolder) viewHolder;
        DouBanMeiZhi list = mData.get(position);
        GlideImgManager.glideLoader(context, list.getUrl(), R.mipmap.ic_launcher, R.mipmap.ic_launcher, holder.imageView, new SizeReadyCallback() {
            @Override
            public void onSizeReady(int width, int height) {
                if (!holder.item.isShown())
                {
                    holder.item.setVisibility(View.VISIBLE);
                }
            }
        });



        holder.content.setText(list.getTitle());
        setupItemClickListener(holder, position);

    }

    class DouBanListHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.imageView)
        ImageView imageView;

        @BindView(R.id.content)
        AppCompatTextView content;

        public View item;

        DouBanListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            item=itemView;

        }

    }

}
